Dart Future operator ==
Syntax & Examples
Future.operator == operator
The equality operator checks if the current Future object is equal to another Future object.
Syntax of Future.operator ==
The syntax of Future.operator == operator is:
operator ==(dynamic other) → boolThis operator == operator of Future the equality operator.
Parameters
| Parameter | Optional/Required | Description |
|---|---|---|
other | required | The Future object to compare with the current Future object for equality. |
✐ Example
1 Equality check for Future objects with same values
In this example,
- We create two Future objects
future1andfuture2, both containing the value 42. - We use the equality operator
==to check iffuture1is equal tofuture2. - We then print the result of the equality check to standard output.
Dart Program
void main() {
Future<int> future1 = Future<int>.value(42);
Future<int> future2 = Future<int>.value(42);
bool areEqual = (future1 == future2);
print('Are future1 and future2 equal? $areEqual');
}Output
Are future1 and future2 equal? false
Summary
In this Dart tutorial, we learned about operator == operator of Future: the syntax and few working examples with output and detailed explanation for each example.